package com.situ.company.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.situ.company.dao.IEmployeeDao;
import com.situ.company.dao.impl.EmployeeDaoImpl;
import com.situ.company.entity.Employee;
import com.situ.company.service.IEmployeeService;
import com.situ.company.util.JSONResult;
import com.situ.company.vo.EmployeeVO;

public class EmployeeServiceImpl implements IEmployeeService{
	private IEmployeeDao employeeDao = new EmployeeDaoImpl();

	@Override
	public JSONResult update(Employee employee) {
		int count = employeeDao.update(employee);
		if (count == 1) {
			return JSONResult.success("更新成功");
		} else {
			return JSONResult.error("更新失败");
		}
	}

	@Override
	public Employee selectById(int id) {
		return employeeDao.selectById(id);
	}

	@Override
	public JSONResult add(Employee employee) {
		int count = employeeDao.add(employee);
		if (count == 1) {
			return JSONResult.success("添加成功");
		} else {
			return JSONResult.error("添加失败");
		}
	}

	@Override
	public JSONResult del(String code) {
		int count = employeeDao.del(code);
		if (count == 1) {
			return JSONResult.success("删除成功");
		} else {
			return JSONResult.error("删除失败");
		}
	}

	@Override
	public JSONResult selectAll(String searchName) {
		ArrayList<EmployeeVO> list = employeeDao.selectAllVO(searchName);
		return JSONResult.success(list);
	}

}
